<Query Kind="Statements" />

string _target = "- DocumentLine 本质是一个红黑树的节点";
CreateXAMLString(_target);
CreateAnnotationString(_target);

void CreateXAMLString(string _target, int _length = 80, char _header_char = '=')
{
	// <!--====================================================================================================-->
	// <!--                                 以下所有内容都是 SVG Image 的资源                                  -->
	// <!--====================================================================================================-->

	string _header = $"<!--{new string(_header_char, _length)}-->";
	int _target_length = 0;
	foreach (char _char in _target)
	{
		_target_length += (IsEnglish(_char) || IsPunctuationOrSpace(_char)) ? 1 : 2;
	}

	int _left = (_length - _target_length) / 2 + 1;
	int _right = (_length - _target_length + 1) / 2 + 1;
	string _message = $"<!--{new string(' ', _left)}{_target}{new string(' ', _right)}-->";

	_header.Dump();
	_message.Dump();
	_header.Dump();
}

void CreateAnnotationString(string _target, int _length = 80, char _header_char = '=')
{
	/* ==================================================================================================== */
	/*                                  以下所有内容都是 SVG Image 的资源                                   */
	/* ==================================================================================================== */

	string _header = $"/* {new string(_header_char, _length)} */";
	int _target_length = 0;
	foreach (char _char in _target)
	{
		_target_length += (IsEnglish(_char) || IsPunctuationOrSpace(_char)) ? 1 : 2;
	}

	int _left = (_length - _target_length) / 2 + 1;
	int _right = (_length - _target_length + 1) / 2 + 1;
	string _message = $"/* {new string(' ', _left)}{_target}{new string(' ', _right)} */";

	_header.Dump();
	_message.Dump();
	_header.Dump();
}

static bool IsChinese(char c)
{
	return (c >= 0x4E00 && c <= 0x9FA5);
}

static bool IsEnglish(char c)
{
	return (c >= 0 && c <= 127);
}

static bool IsPunctuationOrSpace(char c)
{
	// 判断是否为标点符号或空格
	return char.IsPunctuation(c) || char.IsWhiteSpace(c);
}